import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/Index.vue'
import store from '../store/index'



Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  }


 
  ,{path:'/Login',name:'Login',meta:{title:'登录界面'},component:()=>import('../views/Login.vue')},
  {path:'/Index',name:'Index',meta:{title:'欢迎光临奶茶管理系统'},component:()=>import('../views/Index.vue')
,children:[{path:'/user',name:'user',meta:{title:'用户信息'},component:()=>import('../views/Page/user.vue')},
  {path:'/goods',name:'goods',meta:{title:'商品管理'},component:()=>import('../views/goods/Index.vue')},
  {path:'/personage',name:'personage',meta:{title:'个人中心'},component:()=>import('../views/personage.vue')},
  {path:'/Menu',name:'Menu',meta:{title:'菜单管理'},component:()=>import('../views/Menu/Index.vue')},
  {path:'/vip/Index',name:'vippage',meta:{title:'会员'},component:()=>import('../views/vip/Index.vue')},
  {path:'/role',name:'Role',meta:{title:'角色管理'},component:()=>import('../views/Role/Index.vue')},
  {path:'/Pderpage/Index',name:'Pder',meta:{title:'订单报表'},component:()=>import('../views/Pderpage/Index.vue')},
  {path:'/Role',name:'Role',meta:{title:'角色管理'},component:()=>import('../views/Role/Index.vue')},
  {path:'/Dept',name:'Dept',meta:{title:'部门管理'},component:()=>import('../views/Dept/Index.vue')},
  {path:'/GoodControl',name:'GoodControl',meta:{title:'商品控制'},component:()=>import('../views/GoodControl/Index.vue')},
  {path:'/control/order',name:'OrderControl',meta:{title:'点单控制'},component:()=>import('../views/OrderControl/Index.vue')}
   ,{path:'/HJQPder',name:'HJQPder',meta:{title:'订单管理'},component:()=>import('../views/HJQ_Pder/index.vue')},
  ,{path:'/store',name:'store',meta:{title:'店铺信息'},component:()=>import('../views/Address/index.vue')},
  {path:'/ReportForm/VipReportfrom',name:'vipreport',meta:{title:'会员报表'},component:()=>import('../views/Reportform/VipReportfrom.vue')},
  {path:'/din/dindan',name:'/din/dindan',meta:{title:'订单控制台'},component:()=>import('../views/din/dindan.vue')},

  {path:'/HJQ_sales_report',name:'HJQ_sales_report',meta:{title:'销售报表'},component:()=>import('../views/HJQ_sales_report/idnex.vue')}
]
},





]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  //设置标题 
  document.title = to.meta.title;
  if (to.path == '/Login' || store.state.user.Token.length > 0) {
    next()
  } else {
    if (sessionStorage.getItem('zhi') != null) {
      store.commit('SetLogin', JSON.parse(sessionStorage.getItem('zhi')))
      next()
    } else {
      alert('身份信息过期')
      router.push('/Login')
    }

  }
})
export default router
